
// 209.长度最小的子数组
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        // 使用滑动窗口进行解决
        int n = nums.size();
        int sum = 0 , ret = INT_MAX;
        int l = 0;
        for(int r = 0 ; r < n ; r++)
        {
            sum += nums[r];
            while(sum >= target)
            {
                ret = min(ret , r - l + 1);    // [l , r]
                sum -= nums[l++];
            }
        }
        return ret == INT_MAX ? 0 : ret;
    }
};